package com.atguigu.start.teststartmodule19.controller;

import com.atguigu.start.teststartmodule19.event.ProductOnSaleEvent;
import com.atguigu.start.teststartmodule19.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @Autowired
    private ProductService productService;
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @RequestMapping("/product/tradition/{productId}")
    public String productTradition(@PathVariable("productId") Integer productId){
        productService.onSale(productId);
        //核心业务完成后发布事件
        applicationEventPublisher.publishEvent(new ProductOnSaleEvent(productId));
        //传统的业务逻辑，各个业务之间耦合到一起了，响应速度慢且不独立，一旦出现问题就会影响其他业务逻辑
//        productService.putIntoCache(productId);
//        productService.putIntoSearch(productId);
//        productService.putIntoAdQueue(productId);
//        productService.pushToGuest(productId);
        return "ok event upgrade";
    }
}
